greedy implementation strings

Please click on ads to support us..

C++ Code:

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<iomanip>
#include<map>
#include<iterator>
#include<string>
#include<list>
#include<set>
#define int long long
using namespace std;

const int MAXN = 1e5 + 3;
int a[MAXN];
 
void solve() {
	string s; cin >> s;
	int k = 0;
	for (int i = 1; i < s.length(); i++) {
		if (s[i] == s[i - 1]) k++;
	}
	if (k == s.length() - 1)
		cout << "-1\n";
	else cout << s.length() - 1 << '\n';
}	

int32_t main() {
	ios_base::sync_with_stdio(false);
	cout.tie(0); cin.tie(0), cerr.tie(0);
	int t;
	cin >> t;
	//t = 1;
	while (t--)
		solve();
	return 0;
}


Comments

Submit
0 Comments
More Questions

892B - Wrath
999A - Mishka and Contest
727C - Guess the Array
1625C - Road Optimization
1715D - 2+ doors
267A - Subtractions
1582A - Luntik and Concerts
560A - Currency System in Geraldion
946A - Partition
1068B - LCM
1692E - Binary Deque
679A - Bear and Prime 100
488A - Giga Tower
14A - Letter
1150A - Stock Arbitraging
1552A - Subsequence Permutation
1131F - Asya And Kittens
1475F - Unusual Matrix
133B - Unary
1547A - Shortest Path with Obstacle
624A - Save Luke
1238A - Prime Subtraction
1107C - Brutality
1391B - Fix You
988B - Substrings Sort
312A - Whose sentence is it
513A - Game
1711E - XOR Triangle
688A - Opponents
20C - Dijkstra